package com.bootdo.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.system.domain.ChongbitableDO;
import com.bootdo.system.service.ChongbitableService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author xxx
 * @email xxx@xxx.com
 * @date 2021-02-06 16:20:40
 */
 
@Controller
@RequestMapping("/system/chongbitable")
public class ChongbitableController {
	@Autowired
	private ChongbitableService chongbitableService;
	
	@GetMapping()
	@RequiresPermissions("system:chongbitable:chongbitable")
	String Chongbitable(Model model){

		ChongbitableDO chongbitableDO = chongbitableService.get(1);

		model.addAttribute("chongbitableDO",chongbitableDO);

		return "system/chongbitable/chongbitable";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:chongbitable:chongbitable")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ChongbitableDO> chongbitableList = chongbitableService.list(query);
		int total = chongbitableService.count(query);
		PageUtils pageUtils = new PageUtils(chongbitableList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:chongbitable:add")
	String add(){
	    return "system/chongbitable/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:chongbitable:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		ChongbitableDO chongbitable = chongbitableService.get(id);
		model.addAttribute("chongbitable", chongbitable);
	    return "system/chongbitable/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:chongbitable:add")
	public R save( ChongbitableDO chongbitable){
		if(chongbitableService.save(chongbitable)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:chongbitable:edit")
	public R update( ChongbitableDO chongbitable){
		chongbitableService.update(chongbitable);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:chongbitable:remove")
	public R remove( Integer id){
		if(chongbitableService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:chongbitable:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		chongbitableService.batchRemove(ids);
		return R.ok();
	}
	
}
